#!/usr/bin/python3
# -*- coding:utf-8 -*-

#  使用程序去模拟实现一个功能： 把一个网页另存到本地

from urllib.request import  urlopen
from urllib.request import urlretrieve

url="http://www.baidu.com/"

# 打开一个网页
url_response = urlopen(url);

print(url_response)
print(url_response.geturl())
print(url_response.getcode())
print(url_response.info())

url_html = url_response.read();
print(url_html)
url_html = url_html.decode("utf-8")
print(url_html)

# 真正的意图，就是把刚才我们获取到的源码直接保存在c:/mybaidu.html中
save_baidu_html = urlretrieve(url, filename="c:/mybaidu.html")
print(save_baidu_html)

# 抓取图片资源
save_baidu_png = urlretrieve("https://www.baidu.com/img/bd_logo1.png?where=super", "c://mybaidu.png")

